<?php 
	$this->Html->script(array('somente-numeros'), false);
?>

<style>

	.linha_0 {
		background-color: #C1CDCD;
	}
	
	.linha_1 {
		background-color: #EEE8AA;
	}
	
	.numeracao {
		border-collapse: collapse;
		border: 2px solid #4682B4;
	}
	
	.numeracao tbody tr:HOVER {
		background-color: #1E90FF;
		color: white;
	}
	
	.numeracao tbody td {
		border-left: 1px solid #4682B4;
	}	
	
	.titulos {
		font-weight: bold;
		background-color: #4682B4;
		text-align: center;
		color: white;
	}
		
	form .input {
		float: inherit !important;
	    margin-top: 3px;
	    margin-right: 0px !important;
	}	

</style>

<fieldset>
	<legend>Matrícula:</legend>
	<?php 
		echo '<table>';
		echo '<tr><td>Ano:</td><td><b>'   . $matricula['Matricula']['ano'] . '</b></td></tr>';
		echo '<tr><td>Série:</td><td><b>' . $matricula['TipoSerie']['nome'] . '</b></td></tr>';
		echo '<tr><td>Turma:</td><td><b>' . $matricula['Turma']['nome'] . '</b></td></tr>';
		echo '</table>';
	?>
</fieldset>

<fieldset id="fs_avisos" style="display:none;background-color: #FFF68F;">
	<legend style="font-size:30px; color:red; ">Erros:</legend>
	<div id="fs_avisos_conteudo"></div>
</fieldset>

<fieldset>

	<legend>Alunos(as):</legend>
	
	<div id="alunos">
	
		<?php 
		
			echo $this->Form->create('Matricula');
			
			echo '<table width="100%" class="numeracao">';
			echo '<thead>';
			echo '<tr class="titulos"><td colspan="2"><span style="font-size:22px;">Numeração Manual</span></td></tr>';
			echo '<tr class="titulos">';
			echo '<td>No.</td>';
			echo '<td>Aluno(a)</td>';
			echo '</tr>';
			echo '</thead>';
			echo '<tbody>';
		
				$marca = 0;
				
				foreach ($alunos as $key => $aluno) {
					
					echo "<tr class='linha_$marca'>";
					echo '<td align="center" >' .$this->Form->input("aluno_numero", array('type' => 'text', 'name' => "data[$key][Matricula][aluno_numero]", 'value' => $aluno['Matricula']["aluno_numero"], 'class' => 'tamanho5', 'label' => false, 'maxlength' => 3, 'onKeyPress' => 'return SomenteNumero(event)')). '</td>';		
					echo '<td >' . $aluno['Aluno']['nome'] . $this->Form->input('id', array('name' => "data[$key][Matricula][id]", 'type' => 'hidden', 'value' => $aluno['Matricula']['id'])). '</td>';
					echo '</tr>';
					$marca = ($marca == 0) ? 1 : 0;
					 
				}
			echo '</tbody>';
			echo '</table><br />';
			
			echo $this->Form->button('Salvar', array('type' => 'button', 'onclick' => 'javascript:gravar_numeracao_manual();' ));
			echo $this->Form->button('Voltar', array('type' => 'button', 'onClick' => "javascript:location='{$this->request->base}/{$this->request->controller}/matriculas'"));
			echo $this->Form->end();			
		
		?>	
	
	
	</div>
</fieldset>

<script>

	function gravar_numeracao_manual() {

		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: '<?php echo $this->request->base; ?>/matriculas/gravar_numeracao_manual/',
			data: $('#MatriculaNumeracaoManualForm').serialize(),
			async: true,
			beforeSend : function() {
				$('#fs_avisos').hide();
				$('#alunos').css('opacity','0.4');
			},
			success: function(retorno){
				$('#alunos').css('opacity','1');
				window.scrollTo(0, 0);
				if (retorno.sucesso) {
					alert('Numeração gravadas com sucesso!');
				} else {					
					$('#fs_avisos').show().effect('pulsate', 800, 100);
					$('#fs_avisos_conteudo').html(retorno.mensagem);
				}
			},
			error: function(){
				alert('Erro!');
			}
			
		});
	}

</script>